package com.wealth.scsj.p_app.view.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wealth.scsj.p_app.R;
import com.zhy.view.flowlayout.TagFlowLayout;
import com.wealth.scsj.p_app.adapter.EvaluateListAdapter;
import com.wealth.scsj.p_app.bean.EvaluateLabelsBean;
import com.wealth.scsj.p_app.utils.SkipUtils;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 个人中心页面
 * @author qxp
 */
public class MinePageActivity extends BaseActivity implements View.OnClickListener {

    private TextView mToolbarTitle;
    private ImageView mToolbarTitleLeft;
    private ImageView mHeadIv;
    /**
     * 18019871792
     */
    private TextView mMobilePhoneTv;
    /**
     * 杨康
     */
    private TextView mRealNameTv;
    private ImageView mNextIv;
    /**
     * 100分
     */
    private TextView mServicePointsMuchTv;
    private TagFlowLayout mEvaluateFl;
    private RecyclerView mEvaluateRv;

    private RelativeLayout mServicePointsRl;

    List<EvaluateLabelsBean.EvaluateLabels> labelsList =new ArrayList<>();
    List<EvaluateLabelsBean.EvaluateListBean> evaluateListBean =new ArrayList<>();

    EvaluateListAdapter mAdapter;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_mine_page);
    }

    @Override
    protected void initView() {

        mToolbarTitle =  findViewById(R.id.toolbar_title);
        mToolbarTitleLeft =  findViewById(R.id.toolbar_title_left);

        mHeadIv =  findViewById(R.id.head_iv);

        mMobilePhoneTv = findViewById(R.id.mobile_phone_tv);
        mRealNameTv =  findViewById(R.id.real_name_tv);

        mNextIv =  findViewById(R.id.next_iv);
        mServicePointsMuchTv =  findViewById(R.id.service_points_much_tv);
        mEvaluateFl =  findViewById(R.id.evaluate_fl);
        mEvaluateRv = findViewById(R.id.evaluate_rv);
        mServicePointsRl =findViewById(R.id.service_points_rl);
        mEvaluateRv.setLayoutManager(new LinearLayoutManager(
                MinePageActivity.this, LinearLayoutManager.VERTICAL, false));
        //TODO recycleview 分割线未加
    }

    @Override
    protected void initListener() {
        mToolbarTitleLeft.setOnClickListener(this);
        mHeadIv.setOnClickListener(this);
        mRealNameTv.setOnClickListener(this);
        mServicePointsRl.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        mToolbarTitle.setText("个人中心");


        mMobilePhoneTv.setText("180****1792");
        mRealNameTv.setText("杨*柯");
        mServicePointsMuchTv.setText("100分");

        for(int i =0;i<5;i++){
            EvaluateLabelsBean.EvaluateLabels labelsBean =new EvaluateLabelsBean.EvaluateLabels();
            labelsBean.setLabel_name("全部"+i);
            labelsBean.setLabel_num(""+i+1);
            labelsList.add(labelsBean);
        }
        mEvaluateFl.setMaxSelectCount(1);
        mEvaluateFl.setAdapter(new TagAdapter<EvaluateLabelsBean.EvaluateLabels>(labelsList) {

            @Override
            public View getView(FlowLayout parent, int position, EvaluateLabelsBean.EvaluateLabels evaluateLabelsBean) {
                LayoutInflater mInflater = LayoutInflater.from(MinePageActivity.this);
                TextView tv = (TextView) mInflater.inflate(R.layout.mine_evaluate_labels_item,
                        mEvaluateFl, false);
                tv.setText(evaluateLabelsBean.getLabel_name()+"("+evaluateLabelsBean.getLabel_num()+")");
                return tv;
            }

            @Override
            public boolean setSelected(int position, EvaluateLabelsBean.EvaluateLabels evaluateLabels) {
                return evaluateLabels.getLabel_name().equals(labelsList.get(0).getLabel_name());
            }
        });
        mEvaluateFl.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                String selectPos = selectPosSet.toString();
                String currentSelectPos = selectPos.substring(selectPos.indexOf("[")+1, selectPos.indexOf("]"));
                if(Integer.parseInt(currentSelectPos)==0){//选择第0个

                }else{

                }
                //TODO 默认选中，同一个tag重复点击时候选中状态不消失
            }
        });

        mEvaluateFl.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                //TODO 点击对应TAG时候下方recycleview 需要加载对应数据
                return true;
            }
        });

        for (int j =0;j<5;j++){
            EvaluateLabelsBean.EvaluateListBean bean =new EvaluateLabelsBean.EvaluateListBean();
            bean.setUser_name("匿名用户"+j);
            bean.setUser_evaluate_points(j+"颗星");
            bean.setEvaluate_data("2018-05-31 12:34"+j);

            evaluateListBean.add(bean);
        }
        mAdapter =new EvaluateListAdapter(evaluateListBean);
        mEvaluateRv.setAdapter(mAdapter);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.toolbar_title_left:
                finish();
                break;
            case R.id.head_iv:
                break;
            case R.id.real_name_tv:
                break;
            case R.id.service_points_rl:
                SkipUtils.toServicePointsDetails(MinePageActivity.this);
                break;
        }
    }
}
